/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ModelagemView.java
 *
 * Created on 14/10/2009, 09:51:28
 */

package view.processo;

import Util.FabricaConexoes;
import Util.MenusTreeModel;
import Util.ProcAtiv;
import Util.manipulaConexao;
import java.awt.Component;
import java.awt.Font;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreeSelectionModel;
import model.processo.AtivProcDao;
import model.processo.Atividade;
import model.processo.AtividadeDao;
import model.sistema.Usuario;




/**
 *
 * @author Administrador
 */
public class ModelagemView extends javax.swing.JInternalFrame {

    /** Creates new form ModelagemView */
    public ModelagemView(int idprocesso) {
        initComponents();
        id = idprocesso;
        carregaArvore(id);
        status(0);
        int modo = TreeSelectionModel.SINGLE_TREE_SELECTION;
        TreeSelectionModel tsm = jtmodelo.getSelectionModel();
        tsm.setSelectionMode(modo);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtmodelo = new javax.swing.JTree();
        jPanel2 = new javax.swing.JPanel();
        jbtinserirativ = new javax.swing.JButton();
        jbtremoverativ = new javax.swing.JButton();
        jbtadicionarlink = new javax.swing.JButton();
        jbtremoverlink = new javax.swing.JButton();
        Fechar = new javax.swing.JButton();
        jbtnovo = new javax.swing.JButton();
        jbtalteraativ = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtidativ = new javax.swing.JTextField();
        jbtativ = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jtnomeativ = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtdescativ = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jctipo = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jtresp = new javax.swing.JTextField();
        jbtlistaresp = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jctempo = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jftprazo = new javax.swing.JFormattedTextField();
        jbtcancelarativ = new javax.swing.JButton();
        jbtsalvar = new javax.swing.JButton();

        setClosable(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setTitle("Modelagem");
        setToolTipText("");
        setMaximumSize(new java.awt.Dimension(800, 604));
        setMinimumSize(new java.awt.Dimension(800, 600));
        setName(""); // NOI18N
        setVisible(true);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Representação Gráfica"));

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Processo");
        jtmodelo.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane1.setViewportView(jtmodelo);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Controle"));

        jbtinserirativ.setText("Inserir Atividade");
        jbtinserirativ.setEnabled(false);
        jbtinserirativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtinserirativActionPerformed(evt);
            }
        });

        jbtremoverativ.setText("Remover Atividade");
        jbtremoverativ.setEnabled(false);
        jbtremoverativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtremoverativActionPerformed(evt);
            }
        });

        jbtadicionarlink.setText("Adicionar Link");
        jbtadicionarlink.setEnabled(false);
        jbtadicionarlink.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtadicionarlinkActionPerformed(evt);
            }
        });

        jbtremoverlink.setText("Remover Link");
        jbtremoverlink.setEnabled(false);
        jbtremoverlink.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtremoverlinkActionPerformed(evt);
            }
        });

        Fechar.setText("Fechar");
        Fechar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FecharActionPerformed(evt);
            }
        });

        jbtnovo.setText("Novo");
        jbtnovo.setEnabled(false);
        jbtnovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnovoActionPerformed(evt);
            }
        });

        jbtalteraativ.setText("Altera Atividade");
        jbtalteraativ.setEnabled(false);
        jbtalteraativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtalteraativActionPerformed(evt);
            }
        });

        jLabel8.setText("Legenda");

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/redo_edit.gif"))); // NOI18N
        jLabel9.setText("Processo");

        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/configs.gif"))); // NOI18N
        jLabel10.setText("Atividade");

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/activity.gif"))); // NOI18N
        jLabel11.setText("Finalização");

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/welcome_item.gif"))); // NOI18N
        jLabel12.setText("Link");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtinserirativ, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(jbtremoverativ, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(jbtadicionarlink, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(jbtremoverlink, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(jbtnovo, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(jbtalteraativ, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(Fechar, javax.swing.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jbtnovo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbtalteraativ)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtinserirativ)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtremoverativ)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtadicionarlink)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtremoverlink)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Fechar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel11)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12)
                .addGap(63, 63, 63))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados Atividade"));

        jLabel1.setText("Código Atv.");

        jtidativ.setEditable(false);
        jtidativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtidativActionPerformed(evt);
            }
        });

        jbtativ.setText("...");
        jbtativ.setEnabled(false);
        jbtativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtativActionPerformed(evt);
            }
        });

        jLabel2.setText("Nome :");

        jtnomeativ.setEditable(false);
        jtnomeativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtnomeativActionPerformed(evt);
            }
        });

        jLabel3.setText("Descrição:");

        jtdescativ.setColumns(20);
        jtdescativ.setEditable(false);
        jtdescativ.setLineWrap(true);
        jtdescativ.setRows(3);
        jtdescativ.setText(" ");
        jScrollPane2.setViewportView(jtdescativ);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jtidativ, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
                                    .addComponent(jLabel1))
                                .addGap(2, 2, 2)
                                .addComponent(jbtativ, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jtnomeativ, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(118, 118, 118))
                            .addComponent(jLabel3))
                        .addGap(396, 396, 396))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtidativ, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtativ)
                    .addComponent(jtnomeativ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados adicionais"));

        jLabel4.setText("Tipo de execução");

        jctipo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Grupo", "Usuário", "Destinado", "Ativação" }));
        jctipo.setEnabled(false);
        jctipo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jctipoItemStateChanged(evt);
            }
        });
        jctipo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jctipoActionPerformed(evt);
            }
        });

        jLabel5.setText("Responsável :");

        jtresp.setEditable(false);
        jtresp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtrespActionPerformed(evt);
            }
        });

        jbtlistaresp.setText("...");
        jbtlistaresp.setEnabled(false);
        jbtlistaresp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtlistarespActionPerformed(evt);
            }
        });

        jLabel6.setText("Unidade de Tempo");

        jctempo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Segundos", "Minutos", "Horas", "Dias" }));
        jctempo.setEnabled(false);
        jctempo.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jctempoItemStateChanged(evt);
            }
        });

        jLabel7.setText("Prazo");

        jftprazo.setEditable(false);
        jftprazo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
        jftprazo.setToolTipText("");
        jftprazo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jftprazoKeyReleased(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jftprazoKeyTyped(evt);
            }
        });

        jbtcancelarativ.setText("Cancelar");
        jbtcancelarativ.setVisible(false);
        jbtcancelarativ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtcancelarativActionPerformed(evt);
            }
        });

        jbtsalvar.setText("Salvar");
        jbtsalvar.setVisible(false);
        jbtsalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtsalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jctipo, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jctempo, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jftprazo, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jbtsalvar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbtcancelarativ))
                            .addComponent(jtresp, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbtlistaresp, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jctipo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtresp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtlistaresp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jctempo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jftprazo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtcancelarativ)
                    .addComponent(jbtsalvar))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel2, 0, 344, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-800)/2, (screenSize.height-561)/2, 800, 561);
    }// </editor-fold>//GEN-END:initComponents

    private void jbtinserirativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtinserirativActionPerformed

        if(jtidativ.getText().compareToIgnoreCase("") == 0 ||     
           jtnomeativ.getText().compareToIgnoreCase("") == 0 ||
           jtdescativ.getText().compareToIgnoreCase("") == 0 ||
           jtresp.getText().compareToIgnoreCase("") == 0 ||
           jftprazo.getText().compareToIgnoreCase("") == 0
                )
        {
            JOptionPane.showMessageDialog(null, "Há campos não preenchidos, verifique!","Erro",0);
            return;
        }
        int idativ = Integer.valueOf(jtidativ.getText());
        int tipo = jctipo.getSelectedIndex();
        int tempo = jctempo.getSelectedIndex();
        float valor = Float.valueOf(jftprazo.getText());



        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtmodelo.getLastSelectedPathComponent();
        if(node == null) {JOptionPane.showMessageDialog(null, "Não há finalização selecionada, verifique!","Erro",0);return;}
        Object nodeInfo = node.getUserObject();
        //if(!node.isRoot())
        {
            String nome = node.toString();
            String trim = nome.substring(1, 4);
            int chave = Integer.valueOf(trim);
            int vtipo = new AtivProcDao().verificaTipo(id, chave);
            if(vtipo == 1 || vtipo == 4)
            {               
                int next = new AtivProcDao().proximaChave(id);
                if(next == 0) next++;
                try{
                    if(new AtivProcDao().insertAtivFin(id, idativ, next, chave,0,0,tipo,idresp,tempo,valor))
                    {
                        new AtivProcDao().insereFinalizacoes(next, id, idativ);
                    }
                    carregaArvore(id);
                    jbtcancelarativ.doClick();
                    }catch(SQLException e)
                    {
                        JOptionPane.showMessageDialog(null, e.getMessage(),"Erro",0);
                    }

            }
            else
            {
                JOptionPane.showMessageDialog(null,"Não é possivel inserir a Atividade\nSelecione uma Finalização!","Erro",0);
            }
            
            /*if(chave == 2)
            {
                try{
                    new AtividadeDao().insertAtivFin(1, 4, 9,2, 0, 0);
                    status(0); 
                    }catch(SQLException sql)
                    {
                        JOptionPane.showMessageDialog(null, sql.getMessage());
                        status(0);
                    }
            }*/
        }
        //status(0);
    }//GEN-LAST:event_jbtinserirativActionPerformed

    private void jbtadicionarlinkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtadicionarlinkActionPerformed

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtmodelo.getLastSelectedPathComponent();
        if(node == null) {JOptionPane.showMessageDialog(null, "Não há finalização selecionada, verifique!","Erro",0);return;}
        Object nodeInfo = node.getUserObject();
        String nome = node.toString();
        String trim = nome.substring(1, 4);
        int chave = Integer.valueOf(trim);
        int vtipo = new AtivProcDao().verificaTipo(id, chave);
        try {
            if (new AtivProcDao().verificaProcesso(id)) {
                return;
            }
        } catch (SQLException exc) {
            JOptionPane.showMessageDialog(null, exc.getMessage(), "Erro", 0);
        }
        if(vtipo == 1)
        {

            int childs = node.getChildCount();
                for(int i = 0; i < childs; i++)
                {
                    TreeNode no = node.getChildAt(i);
                    if(no.getChildCount() != 0)
                    {
                        JOptionPane.showMessageDialog(null, "Não é possivel inserir link, finalização possuem registros!","Erro",0);
                        return;
                    }
                }

            new ListaLinkView(null, true, this,chave).setVisible(true);

        }

    }//GEN-LAST:event_jbtadicionarlinkActionPerformed

    private void jtidativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtidativActionPerformed
        
    }//GEN-LAST:event_jtidativActionPerformed

    private void jtnomeativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtnomeativActionPerformed
        
    }//GEN-LAST:event_jtnomeativActionPerformed

    private void jtrespActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtrespActionPerformed
        
    }//GEN-LAST:event_jtrespActionPerformed

    private void FecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FecharActionPerformed
        hide();
        getDesktopPane().repaint();
        //new ListaProcView(null, true, this).setVisible(true);
    }//GEN-LAST:event_FecharActionPerformed

    private void jbtremoverativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtremoverativActionPerformed

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtmodelo.getLastSelectedPathComponent();

        //if(node == null) JOptionPane.showMessageDialog(rootPane, "sem selecao");
        Object nodeInfo = node.getUserObject();
        if(!node.isRoot())
        {
            String nome = node.toString();
            String trim = nome.substring(1, 4);
            int chave = Integer.valueOf(trim);
            int tipo = new AtivProcDao().verificaTipo(id, chave);
            
            if(tipo == 0)
            {
                int childs = node.getChildCount();
                for(int i = 0; i < childs; i++)
                {
                    TreeNode no = node.getChildAt(i);
                    if(no.getChildCount() != 0)
                    {
                        JOptionPane.showMessageDialog(null, "Não é possivel remover atividade, finalizações possuem registros!","Erro",0);
                        return;
                    }
                }
                if(new AtivProcDao().verificaLink(chave,id))
                    {
                        if(JOptionPane.showConfirmDialog(null,"Esta atividade possui links\nDeseja remover todos os links?","Links",0) == 0)
                        {
                            try {
                                if (!new AtivProcDao().verificaProcesso(id)) {
                                    new AtivProcDao().deleteLinks(chave, id);
                                    new AtivProcDao().deleteFinalizacoes(chave, id);
                                    new AtivProcDao().deleteAtivFin(id, chave);
                                    carregaArvore(id);
                                }
                            } catch (SQLException exc) {
                                JOptionPane.showMessageDialog(null, exc.getMessage(), "Erro", 0);
                            }
                        }
                        else 
                        {
                            return;
                        }
                    }else
                    {
                        try {
                            if (!new AtivProcDao().verificaProcesso(id)) {
                                new AtivProcDao().deleteFinalizacoes(chave, id);
                                new AtivProcDao().deleteAtivFin(id, chave);
                                carregaArvore(id);
                            }
                        } catch (SQLException exc) {
                            JOptionPane.showMessageDialog(null, exc.getMessage(), "Erro", 0);
                        }
                    }
            }
            else if(tipo == 1)
            {
                JOptionPane.showMessageDialog(null, "Não é possível excluir uma finalização","Atenção!",1);
                return;
                }
            else if(tipo == 2)
                {
                    int childs = node.getChildCount();
                    if(childs != 0)
                        {
                            JOptionPane.showMessageDialog(null, "Não é possível excluir uma finalização","Atenção!",1);
                            return;
                            }
                    if(childs == 0)
                    {
                        JOptionPane.showMessageDialog(null, "Utilize o botão remover Link para esta ação!","Link",1);
                        }

                       }
        }

    }//GEN-LAST:event_jbtremoverativActionPerformed

    private void jbtativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtativActionPerformed
            new ListaAtivView(null, true, this).setVisible(true);
    }//GEN-LAST:event_jbtativActionPerformed

    private void jbtnovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnovoActionPerformed
        status(1);
        limpaCampos();
        jctipo.setSelectedIndex(0);
        jftprazo.setEditable(true);
    }//GEN-LAST:event_jbtnovoActionPerformed

    private void jbtlistarespActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtlistarespActionPerformed
          new ListaTipoExecucao(null, true, this).setVisible(true);
    }//GEN-LAST:event_jbtlistarespActionPerformed

    private void jctipoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jctipoItemStateChanged
            if(jctipo.getSelectedIndex() == 2) 
            {
                jbtlistaresp.setEnabled(false);
                jtresp.setText("Destinado");
                idresp = 0;
            }else if(jctipo.getSelectedIndex() == 3)
            {
                jbtlistaresp.setEnabled(false);
                Usuario user = manipulaConexao.getUsuarioLogado();
                jtresp.setText("Usuário de Ativação");
                idresp = 0;
            }
            else 
            {
                jbtlistaresp.setEnabled(true);
                jtresp.setText("");
            }
    }//GEN-LAST:event_jctipoItemStateChanged

    private void jbtcancelarativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtcancelarativActionPerformed
        jtmodelo.setEnabled(true);
        limpaCampos();
        status(0);
    }//GEN-LAST:event_jbtcancelarativActionPerformed

    private void jctempoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jctempoItemStateChanged
        
        if(jctempo.getSelectedIndex() == 0)
        {
            jftprazo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
            jftprazo.setText("");
        }else{
            jftprazo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0"))));
            jftprazo.setText("");
        }
    }//GEN-LAST:event_jctempoItemStateChanged

    private void jftprazoKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jftprazoKeyReleased

        if(jctempo.getSelectedIndex() == 0 || jctempo.getSelectedIndex() == 1)
        {
            try{
            if(jftprazo.getText().compareToIgnoreCase("") == 0) return;
            if(Integer.valueOf(jftprazo.getText()) > 59)
             {

                 jftprazo.setText("59");
             }
            }catch(NumberFormatException ne)
            {
                jftprazo.setText("59");
            }
        }else if(jctempo.getSelectedIndex() == 2)
        {
            try{
            if(jftprazo.getText().compareToIgnoreCase("") == 0) return;
            if(Integer.valueOf(jftprazo.getText()) > 23)
             {

                 jftprazo.setText("23");
             }
            }catch(NumberFormatException ne)
            {
                jftprazo.setText("23");
            }
        }
        
    }//GEN-LAST:event_jftprazoKeyReleased

    private void jftprazoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jftprazoKeyTyped
         
    }//GEN-LAST:event_jftprazoKeyTyped

    private void jbtremoverlinkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtremoverlinkActionPerformed

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtmodelo.getLastSelectedPathComponent();
        if(node == null) {JOptionPane.showMessageDialog(null, "Não há finalização selecionada, verifique!","Erro",0);return;}
        Object nodeInfo = node.getUserObject();
        String nome = node.toString();
        String trim = nome.substring(0, 1);
        if(trim.compareToIgnoreCase("|")==0) return;
        trim = nome.substring(1, 4);
        int chave = Integer.valueOf(trim);
        int vtipo = new AtivProcDao().verificaTipo(id, chave);
        try {
            if (new AtivProcDao().verificaProcesso(id)) {
                return;
            }
        } catch (SQLException exc) {
            JOptionPane.showMessageDialog(null, exc.getMessage(), "Erro", 0);
        }
        if(vtipo == 2)
        {
            try{
                new AtivProcDao().removeLink(chave, id);
                carregaArvore(id);

                }catch(SQLException s)
                {
                    JOptionPane.showMessageDialog(null, s.getMessage(),"Erro",0);

                }
        }

    }//GEN-LAST:event_jbtremoverlinkActionPerformed

    private void jbtalteraativActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtalteraativActionPerformed

        
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) jtmodelo.getLastSelectedPathComponent();
        if(node == null) {JOptionPane.showMessageDialog(null, "Não há Atividade selecionada, verifique!","Erro",0);return;}
        status(2);
        jbtlistaresp.setEnabled(true);
        Object nodeInfo = node.getUserObject();
        String nome = node.toString();
        String trim = nome.substring(1, 4);
        int chave = Integer.valueOf(trim);
        
        int vtipo = new AtivProcDao().verificaTipo(id, chave);
        
        if(vtipo == 0)
        {
            try{
                ProcAtiv processo = new AtivProcDao().retornaDados(chave, id);
                
                Atividade atividade = new AtividadeDao().getAtividade(processo.getIdativ());
                carregaAtiv(atividade);
                jctempo.setSelectedIndex(processo.getTempo());
                jctipo.setSelectedIndex(processo.getTipo());
                jtresp.setText(new AtivProcDao().retornaResp(processo.getTipo(), processo.getIdtipo()));
                jftprazo.setText(String.valueOf(processo.getValor_tempo()));
                chave_alteracao = chave;
                jtmodelo.setEnabled(false);
                jtresp.setEditable(true);
                jftprazo.setEditable(true);
                }catch(SQLException e)
                {
                    JOptionPane.showMessageDialog(null, e.getMessage(),"Erro",0);
                }
        }
        else {

                jbtcancelarativ.doClick();
                JOptionPane.showMessageDialog(null, "Não há Atividade selecionada, verifique!","Erro",0);
                return;
                }

    }//GEN-LAST:event_jbtalteraativActionPerformed

    private void jbtsalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtsalvarActionPerformed

        if(jtresp.getText().compareToIgnoreCase("") == 0 ||
           jftprazo.getText().compareToIgnoreCase("") == 0
                )
        {
            JOptionPane.showMessageDialog(null, "Há campos não preenchidos, verifique!","Erro",0);
            return;
        }

        try{
            String nome = jtresp.getText();
            int idresponsavel = new AtivProcDao().retornaIdResp(nome, jctipo.getSelectedIndex());

            if(new AtivProcDao().updateAtivFin(jctipo.getSelectedIndex(),idresponsavel, jctempo.getSelectedIndex(), Float.valueOf(jftprazo.getText()), chave_alteracao, id))
            {
                JOptionPane.showMessageDialog(null, "Atividade alterada com sucesso!", "Alteração", 1);
            }
            jbtcancelarativ.doClick();
            }catch(SQLException e)
            {
                JOptionPane.showMessageDialog(null, e.getMessage(),"Erro",0);
                jtmodelo.setEnabled(true);
            }
        
    }//GEN-LAST:event_jbtsalvarActionPerformed

    private void jctipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jctipoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jctipoActionPerformed

    public void carregaArvore(int idp)
    {
        try{
        
        java.sql.PreparedStatement stm;
        ResultSet rs=null;
        ResultSet rs1=null;
                if(!FabricaConexoes.verificaConexao()) FabricaConexoes.getConexao();
                stm = FabricaConexoes.returnStatement("Select * from Processo_Atividade where raiz = 0 and idproc = ? and idfin = 0");
                stm.setInt(1, idp);
                rs = FabricaConexoes.returnResult(stm);
                stm = FabricaConexoes.returnStatement("Select * from Processo where idprocesso = ?");
                stm.setInt(1, idp);
                rs1 = FabricaConexoes.returnResult(stm);
                rs1.next();
                DefaultMutableTreeNode root = new DefaultMutableTreeNode("|000|-"+rs1.getString("nome"));
                preencheArvore(rs, root,idp);
                MenusTreeModel model = new MenusTreeModel(root);
                jtmodelo.setModel(model);
                FabricaConexoes.closeConnection();
                jtmodelo.setCellRenderer(new RenderizarTree());
                for(int i = 0; i< jtmodelo.getRowCount();i++)
                {
                    jtmodelo.expandPath(jtmodelo.getPathForRow(i));
                }

        }catch(SQLException sql)
        {
            JOptionPane.showMessageDialog(null, sql.getMessage());
        }
    }

    public void preencheArvore(ResultSet rs, DefaultMutableTreeNode no,int processoid)
    {
                java.sql.PreparedStatement stm;

        if(rs == null)
        {

            return ;
        }

        DefaultMutableTreeNode no2, no3,no4;

        ResultSet rs1 = rs;
        ResultSet rs2 = null;
        ResultSet rs3 = null;
        ResultSet aux = null;

        try{


        
                while(rs1.next())
                {
                    //inicio do código que nomeia a atividade do link
                   if(FabricaConexoes.verificaConexao())
                        {
                            FabricaConexoes.getConexao();

                        }
                    stm = FabricaConexoes.returnStatement("Select nome from atividade where idatividade = ?");
                    stm.setInt(1, Integer.valueOf(String.valueOf(rs1.getObject("idat"))));
                    aux = FabricaConexoes.returnResult(stm);
                    aux.next();
                    //fim do código que nomeia a atividade do link
                    int id = rs1.getInt("chave");
                    String chave = "";
                    if(id < 10)
                    {
                       chave = "00"+id;
                    }
                    if(id>=10 && id <100)
                    {
                        chave = "0"+String.valueOf(id);
                    }
                    if(id>=100 && id<1000)
                    {
                        chave = String.valueOf(id);
                    }
                    
                    no2 = new DefaultMutableTreeNode("("+chave+")-" + aux.getObject("nome"));
                    
                    if(FabricaConexoes.verificaConexao())
                    {
                        FabricaConexoes.getConexao();
                    }
                    stm = FabricaConexoes.returnStatement("Select * from Processo_Atividade where raiz = ? and idfin != 0 and idproc = ?");
                    stm.setInt(1, Integer.valueOf(String.valueOf(rs1.getObject("chave"))));
                    stm.setInt(2, processoid);
                    rs = FabricaConexoes.returnResult(stm);

                    if(rs != null)
                    {
                        while(rs.next())
                         {

                            //inicio do bloco que nomea as finalizações
                                if(FabricaConexoes.verificaConexao())
                                    {
                                        FabricaConexoes.getConexao();

                                    }
                                stm = FabricaConexoes.returnStatement("Select nome from finalizacao where idfinalizacao = ?");
                                stm.setInt(1, Integer.valueOf(String.valueOf(rs.getObject("idfin"))));
                                aux = FabricaConexoes.returnResult(stm);
                                aux.next();

                                id = rs.getInt("chave");
                                chave = "";
                                if(id < 10)
                                {
                                   chave = "00"+id;
                                }
                                if(id>=10 && id <100)
                                {
                                    chave = "0"+String.valueOf(id);
                                }
                                if(id>=100 && id<1000)
                                {
                                    chave = String.valueOf(id);
                                }

                                no3 = new DefaultMutableTreeNode("["+chave+"]-" + aux.getObject("nome"));
                          //fim do bloco que nomeia as finalizações

                          if(Integer.valueOf(String.valueOf(rs.getObject("link"))) != 0)
                              {
                                boolean proc = false;
                                if(FabricaConexoes.verificaConexao())
                                        {
                                            FabricaConexoes.getConexao();
               
                                        }
                                if(Integer.valueOf(String.valueOf(rs.getInt("processo")))!= 0)
                                {
                                    stm = FabricaConexoes.returnStatement("Select * from processo where idprocesso = "+rs.getObject("link"));
                                    proc = true;
                                }
                                else
                                {
                                    stm = FabricaConexoes.returnStatement("Select * from Processo_Atividade where chave = "+rs.getObject("link")+" and idproc = ?");
                                    stm.setInt(1, processoid);
                                }
                                
                                rs3 = FabricaConexoes.returnResult(stm);

                                rs3.next();
                                //inicio do código que nomeia a atividade do link
                                if(FabricaConexoes.verificaConexao())
                                    {
                                        FabricaConexoes.getConexao();

                                    }
                                if(Integer.valueOf(String.valueOf(rs.getInt("processo")))!= 0)
                                {
                                    aux = FabricaConexoes.returnResult(stm);
                                    aux.next();
                                }
                                else
                                {
                                   stm = FabricaConexoes.returnStatement("Select nome from atividade where idatividade = ?");
                                   stm.setInt(1, Integer.valueOf(String.valueOf(rs3.getObject("idat"))));
                                   aux = FabricaConexoes.returnResult(stm);
                                   aux.next();
                                }
                                

                                //fim do código que nomeia a atividade do link

                                    id = rs.getInt("link");
                                    chave = "";
                                    if(id < 10)
                                    {
                                       chave = "00"+id;
                                    }
                                    if(id>=10 && id <100)
                                    {
                                        chave = "0"+String.valueOf(id);
                                    }
                                    if(id>=100 && id<1000)
                                    {
                                        chave = String.valueOf(id);
                                    }
                                if(proc)
                                {
                                    no4 = new DefaultMutableTreeNode("|"+chave+"|-" + aux.getObject("nome"));
                                }
                                else
                                {
                                    no4 = new DefaultMutableTreeNode("{"+chave+"}-" + aux.getObject("nome"));
                                }
                                no3.add(no4);

                              }
                          if(FabricaConexoes.verificaConexao())
                                    {
                                        FabricaConexoes.getConexao();
               
                                    }
                          stm = FabricaConexoes.returnStatement("Select * from Processo_Atividade where raiz = ? and idfin = 0 and idproc = ?");
                          stm.setInt(1, Integer.valueOf(String.valueOf(rs.getObject("chave"))));
                          stm.setInt(2, processoid);
                          rs2 = FabricaConexoes.returnResult(stm);

                          if(rs2 != null)
                          {
                              preencheArvore(rs2, no3,processoid);
                              no2.add(no3);

                          }//else{no2.add(no3);}
                        }
                    }
                    no.add(no2);
               

                }

        }catch(SQLException e)
        {
            JOptionPane.showMessageDialog(null, e.getMessage());

        }

    }

    public void setId(int id)
    {
        this.id = id;
    }
    public int getId()
    {
        return id;
    }
    public Atividade getAtiv() {
        return ativ;
    }

    public void setAtiv(Atividade ativ) {
        this.ativ = ativ;
    }

    public void carregaAtiv(Atividade ativ)
    {
        jtidativ.setText(String.valueOf(ativ.getId()));
        jtnomeativ.setText(ativ.getNome());
        jtdescativ.setText(ativ.getDescricao());
    }

    
    public void status(int opcao)
    {
        switch(opcao)
        {
            case 0 :
                jbtativ.setEnabled(false);
                jbtlistaresp.setEnabled(false);
                jbtnovo.setEnabled(true);
                jbtalteraativ.setEnabled(true);
                jbtinserirativ.setEnabled(false);
                jbtadicionarlink.setEnabled(true);
                jbtremoverativ.setEnabled(true);
                jbtremoverlink.setEnabled(true);
                
                
                jctempo.setEnabled(false);
                jctipo.setEnabled(false);
                jbtcancelarativ.setVisible(false);
                jbtsalvar.setVisible(false);
                Fechar.setEnabled(true);
                break;
            case 1 :
                jbtativ.setEnabled(true);
                jbtlistaresp.setEnabled(true);
                jbtnovo.setEnabled(false);
                jbtalteraativ.setEnabled(false);
                jbtinserirativ.setEnabled(true);
                jbtadicionarlink.setEnabled(false);
                jbtremoverativ.setEnabled(false);
                jbtremoverlink.setEnabled(false);
                
                
                jctempo.setEnabled(true);
                jctipo.setEnabled(true);
                jbtcancelarativ.setVisible(true);
                jbtsalvar.setVisible(false);
                Fechar.setEnabled(true);
                break;

            case 2 :
                jbtativ.setEnabled(false);
                jbtlistaresp.setEnabled(true);
                jbtnovo.setEnabled(false);
                jbtalteraativ.setEnabled(false);
                jbtinserirativ.setEnabled(false);
                jbtadicionarlink.setEnabled(false);
                jbtremoverativ.setEnabled(false);
                jbtremoverlink.setEnabled(false);
                
                
                jctempo.setEnabled(true);
                jctipo.setEnabled(true);
                jbtcancelarativ.setVisible(true);
                jbtsalvar.setVisible(true);
                Fechar.setEnabled(false);
                break;

        }
    }

    public void limpaCampos()
    {
        jtidativ.setText("");
        jtnomeativ.setText("");
        jtdescativ.setText("");
        jtresp.setText("");
        jftprazo.setText("");
    }

    public int getIdresp() {
        return idresp;
    }

    public void setIdresp(int idresp) {
        this.idresp = idresp;
    }

    public int getIdativ() {
        return idativ;
    }

    public void setIdativ(int idativ) {
        this.idativ = idativ;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Fechar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtadicionarlink;
    private javax.swing.JButton jbtalteraativ;
    private javax.swing.JButton jbtativ;
    private javax.swing.JButton jbtcancelarativ;
    private javax.swing.JButton jbtinserirativ;
    private javax.swing.JButton jbtlistaresp;
    private javax.swing.JButton jbtnovo;
    private javax.swing.JButton jbtremoverativ;
    private javax.swing.JButton jbtremoverlink;
    private javax.swing.JButton jbtsalvar;
    public javax.swing.JComboBox jctempo;
    public javax.swing.JComboBox jctipo;
    private javax.swing.JFormattedTextField jftprazo;
    private javax.swing.JTextArea jtdescativ;
    private javax.swing.JTextField jtidativ;
    public javax.swing.JTree jtmodelo;
    private javax.swing.JTextField jtnomeativ;
    public javax.swing.JTextField jtresp;
    // End of variables declaration//GEN-END:variables
    public int id;
    private Atividade ativ;
    public int idresp;
    public int idativ;
    private int chave_alteracao;



}
class RenderizarTree extends DefaultTreeCellRenderer implements TreeCellRenderer {
    private Font plainFont, italicFont;

    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        String trim = node.toString().substring(0, 1);

        if(trim.compareToIgnoreCase("|")==0) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/redo_edit.gif")));
        }
        if(trim.compareToIgnoreCase("(")==0) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/configs.gif")));
        }
        if(trim.compareToIgnoreCase("[")==0) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/activity.gif")));
        }
        if(trim.compareToIgnoreCase("{")==0) {
            setIcon(new javax.swing.ImageIcon(getClass().getResource("/icones/welcome_item.gif")));
        }

        return this;
    }
}